<%@ page import="main.java.com.entity.Employee" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    // 检查用户是否已登录

//    if (username == null) {
//      response.sendRedirect("login.jsp");
//      return;
//    }else{


%>
<!DOCTYPE html>
<html>


<head>
    <meta charset="UTF-8">
    <title>管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            min-height: 100vh;
            font-family: Arial, sans-serif;
        }

        .sidebar {
            width: 200px;
            background-color: #2D3139;
            color: white;
            padding: 20px 0;
        }

        .logo {
            padding: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .logo img {
            height: 30px;
        }

        .nav-item {
            padding: 15px 20px;
            display: flex;
            align-items: center;
            gap: 10px;
            color: #888;
            text-decoration: none;
            transition: background-color 0.3s;
            background-color: transparent;
        }

        .nav-item.active {
            background-color: #FFB800;
            color: white;
        }

        .nav-item:hover {
            background-color: #363B44;
        }

        .main-content {
            flex: 1;
            background-color: #F5F5F5;
        }

        .header {
            background-color: white;
            padding: 15px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid #eee;
        }

        .user-menu {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .logout-icon {
            cursor: pointer;
            color: #666;
        }
    </style>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="backend/css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="backend/js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="backend/js/bootstrap.min.js"></script>
    <script>
        function setActiveNavItem(element) {
            // 移除所有导航项的 active 类
            document.querySelectorAll('.nav-item').forEach(item => {
                item.classList.remove('active');
            });
            // 为被点击的导航项添加 active 类
            element.classList.add('active');
            // 更新标题
            document.querySelector('.header h1').textContent = element.querySelector('span').textContent;
        }
    </script>
</head>
<body>
<div class="sidebar">
    <div class="logo">
        <img src="backend/image/login-logo.jpg" alt="红灯笼">
        <span>红灯笼</span>
    </div>

    <nav>
        <a href="#" class="nav-item active" onclick="setActiveNavItem(this)">
            <i>👥</i>
            <span>员工管理</span>

        </a>
        <a href="/selectcategory" class="nav-item" onclick="setActiveNavItem(this)">
            <i>📑</i>
            <span>分类管理</span>
        </a>
        <a href="#" class="nav-item" onclick="setActiveNavItem(this)">
            <i>🍽️</i>
            <span>菜品管理</span>
        </a>
        <a href="#" class="nav-item" onclick="setActiveNavItem(this)">
            <i>🎁</i>
            <span>套餐管理</span>
        </a>
        <a href="#" class="nav-item" onclick="setActiveNavItem(this)">
            <i>📋</i>
            <span>订单明细</span>
        </a>
    </nav>
</div>

<div class="main-content">
    <header class="header">
        <h1>员工管理</h1>
        <div class="user-menu">
      <span><%
          List<Employee> username = (List<Employee>) session.getAttribute("list");
          String name = username.get(0).getName();
          out.println(name);
      %></span>
            <a href="backend/login.jsp" class="logout-icon">
                <i>⭕</i>
            </a>
        </div>
    </header>
    <main style="padding: 20px;">
        <form action="${pageContext.request.contextPath}/findEmployeeByPageServlet" method="post">
            <!-- 这里添加员工管理的具体内容 -->
            <input type="text" name="name" value="${name}" ${name == null? name : ''} placeholder="请输入员工姓名">
            <input type="submit" value="查询">
            <button><a href="/backend/add.jsp">添加用户</a></button>
            <table border="1" width="500px">
                <tr>
                    <th>员工姓名</th>
                    <th>账号</th>
                    <th>手机号</th>
                    <th>账号状态</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${pageBean.list}" var="employees" varStatus="s">
                    <tr>
                        <td>${employees.name}</td>
                        <td>${employees.username}</td>
                        <td>${employees.phone}</td>
                        <td>${employees.status}</td>
                        </td>
                        <td>
                            <a href="${pageContext.request.contextPath}/employeebyusernameservlet?id=${employees.id}">修改</a>
                            <a href="javascript:deleteUser('${employees.id}');">删除</a>

                        </td>
                    </tr>
                </c:forEach>
            </table>
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <c:if test="${pageBean.current<=1}">
                    <li class="disabled">
                        </c:if>
                        <c:if test="${pageBean.current>1}">
                    <li>
                        </c:if>
                        <a href="${pageContext.request.contextPath}/findEmployeeByPageServlet?current=${pageBean.current - 1}&rows=5&${name}"
                           aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>

                    <c:forEach begin="1" end="${pageBean.totalpage}" var="i">
                        <c:if test="${pageBean.current == i}">
                            <li class="active"><a
                                    href="${pageContext.request.contextPath}/findEmployeeByPageServlet?current=${i}&rows=5&${name}">${i}</a>

                            </li>
                        </c:if>
                        <c:if test="${pageBean.current != i}">
                            <li>
                                <a href="${pageContext.request.contextPath}/findEmployeeByPageServlet?current=${i}&rows=5&${name}">${i}</a>
                            </li>
                        </c:if>
                    </c:forEach>
<c:if test="${pageBean.current>=pageBean.totalpage}">
                    <li class="disabled">
                        </c:if>
<c:if test="${pageBean.current<pageBean.totalpage}">
                        <li >
</c:if>

                        <a href="${pageContext.request.contextPath}/findEmployeeByPageServlet?current=${pageBean.current + 1}&rows=5&${name}"
                           aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                        <span> 共${pageBean.totalCount}条数据，共${pageBean.totalpage}页</span>
                    </li>
                </ul>
            </nav>
        </form>
    </main>

</div>


<script>
    function deleteUser(id) {
        //用户安全提示
        if (confirm("您确定要删除吗？")) {
            //访问路径
            location.href = "${pageContext.request.contextPath}delUserServlet?id=" + id;
        }
    }
</script>


</body>
</html>

